<?php


namespace App\Http\Repositories\Admin\Base;


use App\Http\Repositories\BaseRepository;
use App\Models\Base\SizeModel;

class SizeRepository extends BaseRepository
{
    public $size;
    public function __construct(SizeModel $size)
    {
        $this->size = $size;
    }

    /**
     * 获取详情
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\ApiException
     */
    public function getSizeInfo($data)
    {
        $where['id'] = $data['id'];

        return $this->size->getInfo($where);
    }

    /**
     * 获取列表
     * @param $data
     * @return mixed
     */
    public function getSizeList($data)
    {
        is_real_exists(@$data['type']) && $where['type'] = $data['type'];
        is_real_exists(@$data['name']) && $where['name'] = ['like', $data['name'].'%'];

        return $this->size->getListByPage($where ?? []);
    }

    /**
     * 添加
     * @param $data
     * @return array
     */
    public function addSize($data)
    {
        return $this->size->addSize($data);
    }

    /**
     * 删除
     * @param $data
     * @return array|string[]
     */
    public function delSize($data)
    {
        return $this->size->deleteItem($data);
    }

    /**
     * 编辑
     * @param $data
     * @return array
     * @throws \App\Exceptions\ApiException
     */
    public function editSize($data)
    {
        $where['id'] = $data['id'];

        return $this->size->editItem($where, $data);
    }
}
